module.exports  = function(grunt) {
    var nowTime = new Date(); 
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            bookLunch_make: {
                //files: {
                    //'build/js/bookLunch.ctrl.min.js':'build/js/bookLunch.ctrl.js',
                    //'build/js/bookLunch.ctrl.min.js':['dist/js/book.ctrl.js', 'dist/js/op.ctrl.js', 'dist/js/register.ctrl.js', 'dist/js/bookRequest.ctrl.js', 'dist/js/deposit.ctrl.js', 'dist/js/cuisineEdit.ctrl.js', 'dist/js/login.ctrl.js', 'dist/js/bookLunch.js'],
                    
                //},
                files: [{
                    expand: true, 
                    cwd: 'build/js',
                    src: '*',
                    dest:'build/js/min', 
                }]
            },
        },

        clean: {
            options:{
                force: true,
            },
            bookLunch_build: ["build/*" ] ,
        },

        concat: {
                options: {
                    separator: ';',
                },
                bookLunch_make: {
                    src: ['dist/js/book.ctrl.js', 'dist/js/op.ctrl.js', 'dist/js/register.ctrl.js', 'dist/js/bookRequest.ctrl.js', 'dist/js/deposit.ctrl.js', 'dist/js/cuisineEdit.ctrl.js', 'dist/js/login.ctrl.js', 'dist/js/bookLunch.js'],
                    dest: 'build/js/bookLunch.ctrl.js',
                },
        },


        copy: {
           bookLunch_make: {
                files: [
                    {expand:true, cwd:'dist/', src: ['css/*'], dest: 'build/'}, // includes files in path and its subdirs 
                    {expand:true, cwd:'dist/js/', src: ['*factory.js', 'utility.js'], dest: 'build/js/'}, // includes files in path and its subdirs 
                ]
           },
           bookLunch_install: {
                files: [
                    {expand:true, src: ['bower_components/**'], dest: '/home/zja/Workspace/ng/bookLunch/'}, // includes files in path and its subdirs 
                    {expand:true,src: ['components/**'], dest: '/home/zja/Workspace/ng/bookLunch/'}, // includes files in path and its subdirs 
                    {expand:true,src: ['pages/**'], dest: '/home/zja/Workspace/ng/bookLunch/'}, // includes files in path and its subdirs 
                    {expand:true,src: ['build/**'], dest: '/home/zja/Workspace/ng/bookLunch/'}, // includes files in path and its subdirs 
                    {src: ['bak/html/index.html'], dest: '/home/zja/Workspace/ng/bookLunch/index.html'}, // includes files in path and its subdirs 
                ]
            }
        },
        cssmin: {
            bookLunch_make: {
                files: [{
                    expand: true,
                    cwd: 'build/css',
                    src: ['*.css', '!*.min.css'],
                    dest: 'build/css',
                    ext: '.min.css'
                }]
            }
        },
        gitadd: {
            ngBookLunch:{
                options: {
                    all: true,
                    cwd: "/home/zja/Workspace/ng/bookLunch/" 
                }
            },
            master:{
                options: {
                    all: true,
                },
            }
        },
        gitcommit: {
            ngBookLunch: {
                options: {
                    cwd: "/home/zja/Workspace/ng/bookLunch" ,
                    message:'<%= gitcommit.ngBookLunch.message %>' 
                    //message: ghPagesCommitMessage 
                },
            },
            master: {
                options: {
                    message:'<%= gitcommit.master.message %>' 
                },
            }
        },
        gitcheckout:{
            current:{
                options:{
                    create: true, 
                    branch: '<%= gitcheckout.current.branch %>'
                },
            } 
        },
        gitpush: {
            ngBookLunch: {
                options: {
                    remote: "origin",
                    branch: "master",
                    cwd: "/home/zja/Workspace/ng/bookLunch" 
                }
            },
            master: {
                options: {
                    remote: "origin",
                    branch: "master",
                }
            }
        },
        gitpull: {
            ghPages: {
                options: {
                    remote: "origin",
                    branch: "gh-pages",
                    cwd: "../FarmPrivateKitchen_gh-pages" 
                }
            },
            master: {
                options: {
                    remote: "origin",
                    branch: "master",
                }
            }
        }
    });

    // 加载包含 "uglify" 任务的插件。
    grunt.loadNpmTasks('grunt-contrib-uglify');
    //这版本copy 不强大
    //grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-copy-mate');
    //grunt.loadNpmTasks('dp-grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-copy');

    grunt.loadNpmTasks('grunt-git');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-cssmin');





    // 默认被执行的任务列表。
    grunt.registerTask('cp', ['copy_mate:ghPages']);
    grunt.registerTask('serve', ['jekyll:master_serve']);
    grunt.registerTask('build', ['jekyll:ghPages_build']);
    //更新另一个目录的gh-pages分支
    grunt.registerTask('gh-cm', ['build', 'clean:ghPages', 'copy_mate:ghPages', 'gitadd:ghPages', 'gitcommit:ghPages']);
    grunt.registerTask('gh-push', ['gh-cm', 'gitpush:ghPages']);
    grunt.registerTask('pull', ['gitpull']);

    //自动生成项目
    grunt.registerTask("make",['clean:bookLunch_build','copy:bookLunch_make','concat:bookLunch_make','uglify:bookLunch_make', 'cssmin:bookLunch_make']);


    //自动生成项目,且安装到默认目录 
    grunt.registerTask("install", ['make', 'copy:bookLunch_install']);

    //git commit and push to server .
    grunt.registerTask("ngBookLunch-push", "grunt ngBookLunch-push --message= ",
                        function () {
                             var message = grunt.option("message");
                             grunt.config.set('gitcommit.ngBookLunch.message', message);
                             grunt.task.run(['gitadd:ngBookLunch','gitcommit:ngBookLunch','gitpush:ngBookLunch']);
                        }
                      );
                                        
};
